﻿#region

using Lab.DataContext.DataContext;

#endregion

namespace Lab.Server.Infrastructure {
    public abstract class Repository<TDomain, TDataObject> where TDataObject : class {
        protected static IDataContext DataContext { get; private set; }

        protected Repository(IDataContext dataContext) {
            DataContext = dataContext;
        }

        public void Save(TDomain domainObject) {
            var dataObject = TranslateToDataObject(domainObject);
            DataContext.InsertInTable(dataObject);
            DataContext.SubmitChanges();
        }

        protected abstract TDataObject TranslateToDataObject(TDomain domainObject);
    }
}